﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using SundUnderviser.ControlLayer;
using SundUnderviser.ModelLayer;
using System.Windows.Forms;

namespace SundUnderviser.GUILayer
{
    public partial class PatientForm : Form
    {
        private List<Underviser> underviserList;
        private List<Patient> patientList;
        private Patient selectedPatient;

        public PatientForm()
        {
            InitializeComponent();
        }

      

        private void button6_Click(object sender, EventArgs e)
        {
            
            PatientControler patientCtrl = new PatientControler();
            if (underviserList == null)
            {
                comboBoxUnderviser.Items.Clear();
                underviserList = patientCtrl.hentAlleUnderviser();
                if (underviserList != null)
                {
                    foreach (Underviser underviserObj in underviserList)
                    {
                        comboBoxUnderviser.Items.Add(underviserObj.Navn);

                    }
                }
            }
            if (selectedPatient != null)
            {
                textBoxNavn.Text = selectedPatient.Navn;
                textBoxPostnr.Text = selectedPatient.Postnr.ToString();
                textBoxTelefonnr.Text = selectedPatient.Telefon.ToString();
                textBoxAdresse.Text = selectedPatient.Adresse;
                textBoxAlder.Text = selectedPatient.Alder.ToString();
                textBoxBy.Text = selectedPatient.Byen;
            }
         
            panel1.Visible = false;
            panel4.Visible = true;

        }

        private void PatientForm_Load(object sender, EventArgs e)
        {
            PatientControler patientCtrl = new PatientControler();
            if (underviserList == null)
            {
                underviserList = patientCtrl.hentAlleUnderviser();
                comboBoxUnderviser.Items.Clear();
                if (underviserList != null)
                {
                    foreach (Underviser underviserObj in underviserList)
                    {
                        comboBoxUnderviser.Items.Add(underviserObj.Navn);

                    }
                }
            }
           
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string navn = textBoxNavn.Text;
            //string adresse = textBoxAdresse.Text;
           
            //string byen = textBoxBy.Text;
            //int alder = 0;
            //int tlf = 0;
            //try
            //{
            //    alder = Convert.ToInt32(textBoxAlder.Text);
            //    tlf = Convert.ToInt32(textBoxTelefonnr.Text);
            //}
            //catch (Exception econvert)
            //{
            //   Console.WriteLine("tlf og alder skal være tal");
            //   Console.WriteLine(econvert);

            //}
            //string inddato = dateTimePicker1.Value.ToString() ;
            //Console.WriteLine("dato " + inddato);
            //string famNavn = textBoxFamilenavn.Text;
            //string famTlf = textBoxFamilieTlf.Text;
            //string famKom = richTextBoxFamileEkstra.Text;
            //int index = comboBoxUnderviser.SelectedIndex;
            //string underviser = underviserList.ElementAt(index).Initialer;
            //PatientControler patientCtrl = new PatientControler();
            //int rc = patientCtrl.OpretPatient(navn, adresse,byen,tlf, alder,famNavn,famTlf,famKom,underviser);
            //if (rc == 1)
            //{
            //    labelMessage.Text = "Patitentens oplysninger er registreret";
            //}
            //else
            //{
            //    labelMessage.Text = "Der er sket en fejl i oprettelsen af oplysningerne";
            //}
        }

        private void panel4_Paint(object sender, PaintEventArgs e)
        {
            UnderviserControler undvCtr = new UnderviserControler();
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            patientList = undvCtr.hentAllePatienter();
            if (patientList != null)
            {
                foreach (Patient patientObj in patientList)
                {
                    listBox1.Items.Add(patientObj.Navn);
                    listBox2.Items.Add(patientObj.Modul.Navn);
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            UnderviserControler undvCtr = new UnderviserControler();
            listBox1.Items.Clear();
            patientList = undvCtr.hentAllePatienter();
            if (patientList != null)
            {
                foreach (Patient patientObj in patientList)
                {
                    listBox1.Items.Add(patientObj.Navn);
                }
            }
            Console.WriteLine("panel 4");
            groupBox4.Visible = false;
          //  groupBoxAnamnese.Visible = false;
            panel4.Visible = false;
            panel1.Visible =true;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            if (index >= 0)
            {
                selectedPatient = patientList.ElementAt(index);
                if (selectedPatient != null)
                {
                    PationeGenerelForm patientObj = new PationeGenerelForm(selectedPatient);
                    patientObj.Show();
                }
             
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBoxAdresse.Text = "";
            textBoxAlder.Text = "";
            textBoxBy.Text = "";
            textBoxFamilenavn.Text = "";
            textBoxFamilieTlf.Text = "";
            textBoxPostnr.Text = "";
            textBoxTelefonnr.Text = "";
            textBoxNavn.Text = "";
            richTextBoxFamileEkstra.Text = "";
            groupBox4.Visible = false;
            selectedPatient = null;
            labelMessage.Text = "";
            
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (selectedPatient != null)
            {
                TemperaturForm tempFormObj = new TemperaturForm(selectedPatient);
                tempFormObj.Show();
            }
            else
            {
                labelMeddelelse.Text = "Der skal vælges en patient først";
            }
        }

        private void buttonHandlinger_Click(object sender, EventArgs e)
        {
            if (selectedPatient != null)
            {
                UdfoertHandlingerForm udfoertObj = new UdfoertHandlingerForm(selectedPatient);
                udfoertObj.Show();
            }
            else
            {
                labelMeddelelse.Text = "Der skal vælges en patient først";
            }
        }

        private void buttonsygehistorik_Click(object sender, EventArgs e)
        {
            if (selectedPatient != null)
            {
                StatusAnkomstForm statusObj = new StatusAnkomstForm(selectedPatient);
                statusObj.Show();
            }
            else
            {
                labelMeddelelse.Text = "Der skal vælges en patient først";
            }
        }

        private void buttonAnamnese_Click(object sender, EventArgs e)
        {
            if(selectedPatient != null)
            {
            AnameseForm anamObj = new AnameseForm(selectedPatient);
            anamObj.Show();
            }
            else
            {
                labelMeddelelse.Text = "Der skal vælges en patient først";
            }
        }

       

        private void buttonAktuelStatus_Click(object sender, EventArgs e)
        {

            if (selectedPatient != null)
            {
                JournalForm jourFormObj = new JournalForm(selectedPatient);
                jourFormObj.Show();
            }
            else
            {
                labelMeddelelse.Text = "Der skal vælges en patient først";
            }
            
        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            PationeGenerelForm patientObj = new PationeGenerelForm(null);
            patientObj.Show();
                 
        }

       

    }
}
